#ifndef _xOutMappingPort_H_
#define	_xOutMappingPort_H_
/*------------------------------------------------------------
  2008/5/18 By YPC
   xMappingNode is of the new mapping node design (please see design document)
   There is no more VVnode and WVnode in this new design.
   "x" means X-man mapping node.
   a xMappingNode can accept abitrary kinds of connections 
   (from WOPs, VMs, collectors, or arithmetic operator
  --------------------------------------------------------------
*/

   
#include <vector>
#include "DIVA_VM.h"
#include "WOP_Entry.h"
#include "xMappingNode.h"
#include "xInMappingPort.h"
#include "xLink.h"
#include "vmLibrary.h"

class xMappingNode ;
class xInMappingPort ;
class xLink ;

class xOutMappingPort {

protected:
	string _name ;	
	string _type ;
	MNClass _class ;
	string _defaultvalue ;

	xMappingNode * _node_parent	;		// the mapping node this port belongs to (can be a wop_entry or mappingnode)
	vector<xLink *> _links ;
	MNCategory _category;				// CATEGORY_NAME, CATEGORY_POSITION, CATEGORY_COLOR, CATEGORY_SCALE, CATEGORY_ROTATION, CATEGORY_SIZE, CATEGORY_OTHER
	
public:
	inline xOutMappingPort(xMappingNode *parent,
		                  string name, 
						  string type, 
						  MNClass    classp,
						  string defaultvalue,
						  MNCategory	 category) 
	{ _name = name ; _type = type ; _node_parent = parent; _class = classp ; _defaultvalue = defaultvalue ; _category = category; } 

	inline xOutMappingPort(string type, xMappingNode *parent) { 
		  _name = type ; 
		  _type = type ;
		  _class = CLASS_REQUIRED ;
		  _defaultvalue = "" ;
		  _node_parent = parent; 
		  _category = CATEGORY_OTHER;
	 }
	xOutMappingPort(string name, WOP_Entry* parent) { _name = name ; _node_parent = NULL ;  }

	inline xMappingNode * getParent() { return _node_parent ; }
	inline string getName() { return _name ; }
	inline void setCategory(MNCategory category) { _category = category; }
	inline MNCategory getCategory() { return _category; }
	inline void   setName(string name) { _name = name ; }
	inline string getType() { return _type ; }
	inline MNClass getClass() { return _class ; }
	inline void setClass(MNClass classtype) { _class = classtype ; }
	inline string getDefaultValue() { return _defaultvalue ; }

	/** add a link to this port */
	void add_link(xLink *p) { _links.push_back(p); }

	/** remove a link from this port */
	void remove_link(xLink *p) {
		vector<xLink*>::iterator itr ;
		for (itr = _links.begin(); itr != _links.end(); itr++) {
			if ((*itr) == p) { _links.erase(itr) ; return ;}
		}
	    return ;
	}

	/** get all the links attached to this port */
	inline vector<xLink *> getLinks() { return _links ; } 

	int getIndexOfParent() ;

	
};
#endif 